<template>
  <el-container>
    <el-header>
      <div class="logo">
        <img src="../assets/img/heima.png" alt="电商后台管理系统" />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="signOut">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="calculatedWidth">
        <div class="toggle-button" @click="toggleCollapse">
          |||
        </div>
        <aside-lin
          :menuList="menuList.data"
          :isCollapse="isCollapse"
        ></aside-lin>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import AsideLin from "../components/AsideLin.vue";
import { requestGet } from "../request/request";
export default {
  components: { AsideLin },
  name: "",
  data() {
    return {
      menuList: [],
      isCollapse: false
    };
  },
  created() {
    this.getMenuList();
  },
  computed: {
    // 折叠时计算宽度
    calculatedWidth() {
      return this.isCollapse ? 64 + "px" : 200 + "px";
    }
  },
  methods: {
    // 退出登录功能
    signOut() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    // 加载侧边导航列表
    async getMenuList() {
      let { data: res } = await requestGet("/menus");
      this.menuList = res;
      console.log(res);
    },
    // 点击折叠按钮
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    }
  }
};
</script>
<style lang="scss" scoped>
.el-header {
  background-color: #373d3f;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .logo {
    display: flex;
    justify-content: center;
    align-items: center;
    span {
      color: #fff;
      font-size: 25px;
      margin-left: 20px;
    }
  }
}
.el-aside {
  background-color: #323743;
  cursor: pointer;
  transition: 0.5;
}
.el-main {
  background-color: #e9edf0;
}
.el-container {
  height: 100vh;
  .toggle-button {
    color: #fff;
    background-color: #4a5064;
    padding: 5px;
    text-align: center;
    font-size: 14px;
    letter-spacing: 2px;
  }
}
</style>
